﻿@using FCZLM.Core.Models
@model IEnumerable<FCZLM.Core.Models.ProductUrls>
@{
    Layout = null;
    var products = ViewBag._producturlsRepository as List<Products>;
}
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="/layui/css/layui.css" rel="stylesheet" />
</head>
<body>
    
    <div>
        <div class="demoTable layui-form">
          
          
            <button class="layui-btn layui-btn-primary" id="btnAdd">添加</button>
        </div>
        <table id="demo" lay-filter="test"></table>
    </div>

    <table id="demo" lay-filter="test"></table>
    <style type="text/css">
        layui-table-ce11 {
            text-align: center;
            height: auto;
            white-space: normal;
        }

        layui-table img {
            max-height: 200px;
        }
    </style>
    <script src="/layui/layui.js"></script>

    <script>
        layui.use('table', function () {
            var table = layui.table;
            //第一个实例
            table.render({
                elem: '#demo'
                , height: 312
                , url: '/fproducturls/index' //数据接口
                , page: true//开启分页
                , method: "post"
                , cols: [[ //表头
                    { field: 'id', title: 'ID', width: 80, sort: true, fixed: 'left' }
                    , { field: 'productId', title: '图片名称', width: 150 }
                    , { field: 'picUrl', title: '图片', templet: "<div><img src='{{d.picUrl}}'></div>",width:120 }
                    , { field: 'picType', title: '图片类型', width: 150 }
                    , { field: 'createTime', title: '发布时间', width: 200, sort: true }
                    , { title: '操作', templet: " <span><a lay-event='edit' class='layui-btn layui-btn-warm layui-btn-xs'>编辑</a><a class='layui-btn layui-btn-danger layui-btn-xs' lay-event='del'>删除</a></span>", width: 200 }
                ]],
                initSort: {
                    field: 'id'
                    , type: 'desc'
                },
                page: true,
                limit: 100,
                id: "newsList"
            });
            var $ = layui.$, active = {
                reload: function () {
                    var picurl = $('#picurl');

                    //执行重载
                    table.reload('newsList', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            picurl: picurl.val(),

                        }
                    });
                }
            };

            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            table.on('tool(test)', function (obj) { // 注：test 是 table 原始标签的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                if (layEvent === 'del') { //删除
                    layer.confirm('确定删除吗？', function (index) {
                        $.post("/fproducturls/del", { id: data.id }, function (res) {
                            if (res.isSuccess) {
                                layer.msg(res.msg, function () {
                                    table.reload("newsList");
                                });
                            } else {
                                layer.msg(res.msg);
                            }

                        })
                    });
                } else if (layEvent === 'edit') {
                    var index = layer.open({
                        type: 2,
                        content: '/fproducturls/edits/' + data.id,
                        area: ["500px", "600px"]
                    });
                }
            });
            $("#btnAdd").on("click", function () {
                var index = layer.open({
                    type: 2,
                    content: '/fproducturls/add',
                    area: ["500px", "600px"]
                });
            })

        });

    </script>
    </div>
</body>
</html>
